package cn.tedu.test.charging.websocket.controller;

import cn.tedu.test.charging.websocket.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {
    @Autowired
    private WebSocketServer webSocketServer;
    /**
     * 当 用户 对 主播 进行关注动作
     * webSocket给主播发送消息
     */
    @GetMapping("/focus/{userId}/{focusedUserId}")
    public String focus(@PathVariable("userId") Integer userId,
                        @PathVariable("focusedUserId") Integer focusedUserId){
        //1.记录 粉丝 记录 谁关注数
        //2.给focusedUserId 有人关注你了
        String messageTemplate="你好:"+focusedUserId+";"+userId+",关注了你";
        webSocketServer.pushMessage(focusedUserId,messageTemplate);
        return "success";
    }
}
